package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.NetworkInterface;
import com.accelstack.cmp.repository.NetworkInterfaceRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 网卡Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class NetworkInterfaceService {
    
    private final NetworkInterfaceRepository networkInterfaceRepository;
    
    @Transactional
    public NetworkInterface create(NetworkInterface networkInterface) {
        return networkInterfaceRepository.save(networkInterface);
    }
    
    @Transactional
    public NetworkInterface update(NetworkInterface networkInterface) {
        return networkInterfaceRepository.save(networkInterface);
    }
    
    @Transactional
    public void deleteById(Long id) {
        networkInterfaceRepository.deleteById(id);
    }
    
    public Optional<NetworkInterface> findById(Long id) {
        return networkInterfaceRepository.findById(id);
    }
    
    public List<NetworkInterface> findAll() {
        return networkInterfaceRepository.findAll();
    }
    
    public Page<NetworkInterface> findAll(Pageable pageable) {
        return networkInterfaceRepository.findAll(pageable);
    }
    
    public List<NetworkInterface> findByServerId(Long serverId) {
        return networkInterfaceRepository.findByServerId(serverId);
    }
}

